<?php

namespace app\admin\model;

use think\Cache;
use think\Db;
use think\Model;

class KuaiDiUserModel extends Model {

    public function getUserInfo($userName, $pass)
    {
        $where = [
            'user_name' => $userName,
            'password' => md5($pass),
            'is_login_admin' => 1,
        ];
        $info = Db::table('kuaidi_user')->where($where)->find();
        if (empty($info)) {
            $res['success'] = false;
            $res['desc'] = '密码错误或没有权限访问';
            $res['errorcode'] = '200001';
            return $res;
        }
        $info['avatar'] = $_SERVER['HTTP_HOST'] . "/image/icon.jpeg";

        $access_token = md5(uniqid() . mt_rand());
        $info['token'] = $access_token;
        Cache::set($access_token, $info, 86400 * 10);
        $res['success'] = true;
        $res['desc'] = '';
        $res['errorcode'] = '';
        $res['data'] = $info;
        return $res;

    }

    public function upUserInfo(array $upData, array $where)
    {
        $res['success'] = false;
        $res['desc'] = '操作失败';
        $res['errorcode'] = '200022';
        if (empty($upData) || empty($where)) return $res;
        $ret = Db::table('kuaidi_user')->where($where)->update($upData);
        $res['success'] = true;
        $res['desc'] = '操作成功';
        $res['errorcode'] = '';
        return $res;
    }


}